{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "bfd997ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pythonlib import toolean\n",
    "from pythonlib import toolean_net"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "bb8f54ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "2904fc9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import importlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "3ce8730a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'pythonlib.toolean' from 'd:\\\\00synchronize\\\\tnn\\\\pythonlib\\\\toolean.py'>"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "importlib.reload(toolean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "63ad0e64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'pythonlib.toolean_net' from 'd:\\\\00synchronize\\\\tnn\\\\pythonlib\\\\toolean_net.py'>"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "importlib.reload(toolean_net)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "d222aa26",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# 示例：生成一个 5x5 的随机矩阵\n",
    "n = 5\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "1be27de3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "([1, -1, -1, -1, 1], [0, 1, 0, 0, -1])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# 示例：生成一个长度为 10 的三值数组\n",
    "tv1=toolean.rand_tv(n)\n",
    "tv2=toolean.rand_tv(n)\n",
    "\n",
    "tv1,tv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "38d40226",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[-1, 1, 1, 1, -1]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.otimes_tv_t(tv1,-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "148e833d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, -1, 0, 0, -1]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp=[toolean.otimes_t_t(x,y) for x,y in zip(tv1,tv2)]\n",
    "temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "ebd04882",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.otimes_tv_tv(tv1,tv2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "700f0604",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[ 1, -1, -1,  0,  0],\n",
       "        [-1,  0,  1,  1,  0],\n",
       "        [-1,  0,  1,  0,  0],\n",
       "        [ 1,  0,  0, -1,  1],\n",
       "        [ 1, -1,  0,  1,  1]]),\n",
       " array([[ 1, -1, -1,  1,  1],\n",
       "        [-1,  1, -1,  0, -1],\n",
       "        [-1,  0, -1,  0,  1],\n",
       "        [ 0, -1,  0,  0,  1],\n",
       "        [ 1,  1, -1,  0, -1]]))"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r1 = toolean.rand_tm(n,n)\n",
    "r2 = toolean.rand_tm(n,n)\n",
    "r1,r2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "e51a1e42",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([-1,  1,  1,  0,  0]),\n",
       " array([ 1,  0, -1, -1,  0]),\n",
       " array([ 1,  0, -1,  0,  0]),\n",
       " array([-1,  0,  0,  1, -1]),\n",
       " array([-1,  1,  0, -1, -1])]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[x*(-1) for x in r1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "0f977673",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1, -1,  1,  1,  1],\n",
       "       [-1,  0,  0, -1,  1],\n",
       "       [-1,  1,  0, -1,  0],\n",
       "       [ 1,  1, -1,  1, -1],\n",
       "       [ 1, -1, -1,  1,  1]])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.otimes_tm_tm(r1,r2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "0c0d2936",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, -1, 1, 1, 0]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.otimes_tv_tm(tv1,r2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "f23a51cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, -1, -1, 1, 1]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.otimes_tm_tv(r1,tv1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "df227e3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, -1, 0, 0, -1]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.qtimes_tv_tv(tv1,tv2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34188eeb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "6576bf55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.otimes_tv_tv(tv1,tv2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "1e829cc9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[-1, 1, 1, 0, 0],\n",
       " [1, 0, -1, -1, 0],\n",
       " [1, 0, -1, 0, 0],\n",
       " [-1, 0, 0, 1, -1],\n",
       " [-1, 1, 0, -1, -1]]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.otimes_tm_t(r1,-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "98a4ee93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[-1, 1, 1, 0, 0],\n",
       " [1, 0, -1, -1, 0],\n",
       " [1, 0, -1, 0, 0],\n",
       " [-1, 0, 0, 1, -1],\n",
       " [-1, 1, 0, -1, -1]]"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.otimes_tm_t(r1,-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "773ae3c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, -1, 0, 0, -1]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.qtimes_tv_tv(tv1,tv2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "b91d4ca6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  1,  1, -1,  1],\n",
       "       [-1, -1,  1,  0, -1],\n",
       "       [-1,  0,  1,  0,  1],\n",
       "       [ 0,  1,  0,  0,  1],\n",
       "       [ 1, -1,  1,  0, -1]])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolean.qtimes_tv_tm(tv1,r2)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ana",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
